﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;
using CNotebook.Sales;
namespace NotebookS2
{
    public partial class M_ADDPRICELIST : RibbonForm
    {
        public M_ADDPRICELIST()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }
        public string PriceListCode { get; set; }

        private void btnAddPriceList_Click(object sender, EventArgs e)
        {
            PriceUnit oUnit = new PriceUnit();
            PriceManager oManager = new PriceManager();

            oManager.ConnectionString = this.ConnectionString;

            oManager.Open();

            if (oManager.IsPriceListCodeExists(txtPriceListCode.Text) == false)
            {
                if (oManager.IsPriceListNameExists(txtPriceListName.Text) == false)
                {
                    oUnit.PriceListCode = txtPriceListCode.Text;
                    oUnit.PriceListName = txtPriceListName.Text;
                    oUnit.Remarks = txtRemarks.Text;
                    oUnit.BasePriceList = txtPriceList.Text;
                    oUnit.Factor = txtFactor.Text;

                    oManager.AddNewPriceListCode(oUnit);
                    oManager.Close();

                    this.PriceListCode = txtPriceListCode.Text;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Price List Name is already exists!!!!", "Price List", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtPriceListName.Focus();
                    txtPriceListName.SelectAll();
                }

            }
            else
            {
                MessageBox.Show("Price List Code is already exists!!!!", "Price List", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtPriceListCode.Focus();
                txtPriceListCode.SelectAll();
            }


        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void M_ADDPRICELIST_Load(object sender, EventArgs e)
        {
            
        }

        private void txtPriceList_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            FND_PLN oForm = new FND_PLN();

            oForm.ConnectionString = this.ConnectionString;

            oForm.ShowDialog();

            if (oForm.PriceListCode != null)
            {
                txtPriceList.Text = oForm.PriceListCode;
            }
        }
    }
}
